package com.jumi.microservice.material.service.impl;

import com.jumi.microservice.common.exception.ExceptionSupply;
import com.jumi.microservice.common.exception.ExceptionType;
import com.jumi.microservice.material.domain.JmDict;
import com.jumi.microservice.material.domain.JmDictValue;
import com.jumi.microservice.material.mapper.JmDictMapper;
import com.jumi.microservice.material.mapper.JmDictValueMapper;
import com.jumi.microservice.material.service.JmDictValueService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author ssk
 * @create 2020/8/4 10:36
 **/
@Service
public class JmDictValueServiceImpl implements JmDictValueService {

    @Resource
    private JmDictValueMapper dictValueMapper;

    @Resource
    private JmDictMapper dictMapper;

    @Override
    public List<JmDictValue> findListByDictId(Long dictId) {
        return dictValueMapper.findListByDictId(dictId);
    }

    @Override
    public List<JmDictValue> findListByDictCode(String dictCode) {
        try {
            JmDict dict = dictMapper.findByCode(dictCode);
            return dictValueMapper.findListByDictId(dict.getDictId());
        } catch (Exception e) {
            throw new ExceptionSupply(500, "sql错误!").newException();
        }
    }

	@Override
	public Integer findIdByName(String valueName)
	{
		return dictValueMapper.findIdByName(valueName);
	}

    @Override
    public JmDictValue findById(Long valId) {
        return dictValueMapper.findById(valId);
    }

	@Override
	public String findNameById(Integer valId)
	{
		return dictValueMapper.findNameById(valId);
	}
}
